package inl.resilienceManager.qmul.gemom;

import java.awt.Frame;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JTree;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;

import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JTextField;

import resilienceManager.qmul.gemom.Gbroker;
import resilienceManager.qmul.gemom.NSitem;
import resilienceManager.qmul.gemom.XMLfilter;
import resilienceManager.qmul.gemom.scParser;

import cbr.resilienceManager.qmul.gemom.CbrData;
import ac.uk.qmul.gemom.scenario.AutoSubscriber;
import ac.uk.qmul.gemom.scenario.DemoResource;
import ac.uk.qmul.gemom.scenario.Subscription;
import ac.uk.qmul.gemom.scenario.ScenarioFileParser;
import ac.uk.qmul.gemom.scenario.TextFile;
/**
 * the class for the name space initialization
 * 
 * load the gbroker
 * load the namespace
 * 
 * find the best solution
 * 
 * COPYRIGHT DISCLAIMER
 * Synopsis: All the source codes presented in this document are intellectual
 * properties of Queen Mary, University of London.
 * 
 * @year 2010
 * @author Peng Jiang, John Bigham, Jiayi Wu Jinfu Wang------------QMUL
 * @version 1.0 
 */

public class iniFrame extends JFrame {
	
	// static variables used to store state of different windows and GUI components,
	// also used as a mean of simple communication
	public static boolean brokerConfigured;

	private static final long serialVersionUID = 1L;
	private JTabbedPane jTabbedPane = null;
	private JScrollPane jScrollPane = null;
	private JTable jTable = null;
	private JPanel jPanel = null;
	private JButton jButton = null;
	private JButton jButton_modify = null;
	private JButton jButton_delete = null;
	private JPanel jPanel_gbroker = null;
	private JPanel jPanelAnalyzer = null;
	private JPanel jPanelAnalyzerControl = null;
	private JScrollPane jScrollPaneAnalyzer = null;
	private JButton analyzeCovButton = null;
	private JButton openScenarioButton = null;
	private JButton startAnalyzerButton = null;
	private JButton analyzeFileButton = null;
	private JButton jButton_load = null;
	private treePanel jPanel_namespace = null;
	private Dialog dialog_gbroker = null;  //  @jve:decl-index=0:visual-constraint="232,-41"
	private JButton dialog_add = null;
	private JPanel jPanel_button = null;
	private JButton dialog_no = null;
	private JPanel jPanel_label = null;
	private JLabel jLabel_cap = null;
	private JTextField jTextField_cap = null;
	private JLabel jLabel_threshold = null;
	private JTextField jTextField_th = null;
	
	
	private ScenarioFileParser scenarioParser; 
	private File file;
	private AutoSubscriber autoSubscriber;
	private JPanel autoSubscriberPane;
	
	// the 
	private gTable gt;
	private Dialog d;
	
	private String publisherStatus;
	
	private varTable vt;
	
	private itemTable itable;
	
	// the JPanel used for the Pie-3D
	private nsPie np;
	
	// the JPanel used for the solution
	private iniSolution inS;
	
	private iniRisk irisk;
	
	private double pc=0;
	private double pth=0;
	
	private boolean modify=false;
	
	private boolean loggingStarted = false;
	
	private boolean shouldIgnoreLoggingSignal = false;
	
	private CbrData cd=new CbrData(0,true);
	
	private double[][] msgRate = null;
	
	private String[] namespaces = null;
	
	
	
	/**
	 * used by the auction part, to get the information of gbroker
	 * 
	 * @return Gbroker[]: the list of the gbroker
	 * **/
	
	public Gbroker[] getGlist(){
		
		Gbroker[] glist=new Gbroker[gt.getGlist().size()];
		for(int i=0; i<glist.length; i++)
		{
			glist[i]=gt.getGlist().get(i);
		}
		
		return glist;
	}
	
	public String[] getNS(){
		return namespaces;
	}
	
	
	/*
	 * This is the default constructor
	 */
	public iniFrame() {
		super("Initial-allocation Control");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setLayout(new BorderLayout());
		//this.setSize(800, 450);

		this.setBounds(10, 10, 1200, 600);
		this.add(getJTabbedPane(), BorderLayout.CENTER);
		
		Dimension scr = Toolkit.getDefaultToolkit().getScreenSize(); 
		Dimension frm = this.getSize(); 
		setLocation( (scr.width - frm.width) / 2, 
				(scr.height - frm.height) / 2 - 18); 
		
	}

	/**
	 * This method initializes jTabbedPane	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			
			
			jTabbedPane.addTab("Message Rate Analyzer", null, getJPanelAnalyzer(), null);
			jTabbedPane.addTab("Gbroker Configuration", null, getJPanel_gbroker(), null);
			jTabbedPane.addTab("Namespace Set Partitioner", null, getJPane_namespace(), null);
		}
		return jTabbedPane;
	}
	
	/***
	 * this method build the variance table for each name space
	 * 
	 * 
	 * **/
	public void createVTable(){
		 
		jTabbedPane.addTab("Variance Table", null, getVarPane(), null);
		
	}
	
	
	/**
	 * This method build the chart 3D panel
	 * 
	 * 
	 * */
	
	public void createPie(NSitem[] items){
		
		JPanel nsPanel=nsPie.createPanel(items);
		jTabbedPane.addTab("Items", null, nsPanel, null);
		
	}
	
	/**
	 * This method build the table for the variance of the item
	 * 
	 * */
	
	public void createItemTable(NSitem[] items)
	{
		
		itable = new itemTable(items);
		JPanel itemPanel= itable.getPane();
		jTabbedPane.addTab("Items Variance", null, itemPanel, null);
	}
	
	
	/**
	 * 
	 * **/
	
	public void getSolution(solution[] sl,Gbroker[] glist){
		
		JPanel soPanel=inS.createPanel(sl, glist);
		jTabbedPane.addTab("Solution", null, soPanel, null);
		
	}
	
	/**
	 * 
	 * **/
	
	public void getRisk(solution[] sl,Gbroker[] glist){
//FIXME create risk panel iniRisk		
		JPanel soPanel=irisk.createPanel(sl, glist);
		jTabbedPane.addTab("Risk", null, soPanel, null);
		
	}
	
	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTable	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private JTable getJTable() {
		if (jTable == null) {
			
			gt= new gTable();
			
			jTable = gt.getTable();
			
		}
		return jTable;
	}
	
	/**
	 * This method initializes variance Table
	 * 	
	 * @return javax.swing.scrooltable	
	 */
	private JPanel getVarPane() {
		System.out.println("getVarPane");
		JPanel vp=null;
		if (vt == null) {
			
		//TODO  when you first run, uncommon the below line

			
		// when you finish the first run,, common the below line
//			TableSaver.Creat();
//			TableSaver.Saving(TableSaver.getRandTable());
			vt = new varTable(TableSaver.Loading());
//			vt = new varTable(TableSaver.loadMatrix());
			
			vp= vt.getTable();
			

		}
		return vp;
	}
	

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			GridLayout gridLayout = new GridLayout();
			gridLayout.setRows(1);
			jPanel = new JPanel();
			jPanel.setLayout(gridLayout);
			jPanel.add(getJButton_load(), null);
			jPanel.add(getJButton(), null);
			jPanel.add(getJButton_modify(), null);
			jPanel.add(getJButton_delete(), null);
		}
		return jPanel;
	}
	
 
	
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelAnalyzerControl() {
		if (jPanelAnalyzerControl == null) {
			GridLayout gridLayout = new GridLayout();
			gridLayout.setRows(1);
			jPanelAnalyzerControl = new JPanel();
			jPanelAnalyzerControl.setLayout(gridLayout);
			  
			openScenarioButton = new JButton("Open scenario");
			openScenarioButton.addActionListener(new java.awt.event.ActionListener(){
				public void actionPerformed(ActionEvent event) {
					if(loadScenario()){
					    initSubscriber();
					    startAnalyzerButton.setEnabled(true);
					    analyzeCovButton.setEnabled(false);
					}
				}
			});
			
			startAnalyzerButton = new JButton("Start data analysis");
			startAnalyzerButton.addActionListener(new java.awt.event.ActionListener(){
				public void actionPerformed(ActionEvent event) {
					autoSubscriber.initSubscription(); 
					autoSubscriber.onStartCounter();
					startAnalyzerButton.setEnabled(false);
					analyzeCovButton.setEnabled(false);

				}
			});
			
			analyzeCovButton = new JButton("Save & analyze covariance matrix");
			analyzeCovButton.addActionListener(new java.awt.event.ActionListener(){
				public void actionPerformed(ActionEvent event) {
					//divideSelectedItems(true,null);
					if(convertTrainingDataToCovariance())
					    analyzeCovButton.setEnabled(false);
				}
			});
 
			analyzeFileButton = new JButton("Analyze from file");
			analyzeFileButton.addActionListener(new java.awt.event.ActionListener(){
				public void actionPerformed(ActionEvent event) {  
					// support for training from existing data files
					convertFileDataToCovariance();

				}
			});

			// this two buttons have to be disabled until the subscriber has been
			// initialised
			 
			startAnalyzerButton.setEnabled(false);
			analyzeCovButton.setEnabled(false);
			
			jPanelAnalyzerControl.add(openScenarioButton);
			jPanelAnalyzerControl.add(startAnalyzerButton);
			jPanelAnalyzerControl.add(analyzeCovButton); 
			jPanelAnalyzerControl.add(analyzeFileButton); 
			
		}
		return jPanelAnalyzerControl;
	}
	
	private void initSubscriber(){
		Subscription sub = new Subscription("default host");
		for(int i = 0; i < scenarioParser.nsList.size(); i ++){
		    sub.addNamespace(scenarioParser.nsList.get(i));
		}
		this.autoSubscriber.reset();
		this.autoSubscriber.initialiseStartupParameters(scenarioParser, sub);
		   
		//Dimension frm = jScrollPaneAnalyzer.getSize(); 
		//autoSubscriber.setSize( frm.width, frm.height); 
		
		//this.jScrollPaneAnalyzer.setViewportView(autoSubscriber);
		//jScrollPaneAnalyzer.setSize(1200,600);
		
		//this.autoSubscriberPane = autoSubscriber;
		//this.validate();
		//add(autoSubscriber); 
		
	}
	
	// receive command from subscribers, signify the end of training data series
	public void receiveCommand(String status){
		this.publisherStatus = status;
		//System.out.println("here is " + status);
		executeCommand();
	}

	
	private void executeCommand(){ 
		
		if (publisherStatus.equalsIgnoreCase(DemoResource.PUBLISHER_STATUS_STARTING)){
			shouldIgnoreLoggingSignal = false;
		}
		
		 
		if (publisherStatus.equalsIgnoreCase(DemoResource.PUBLISHER_STATUS_SENDING)
				&& !shouldIgnoreLoggingSignal){

			// this signal is only used once, and is reset when new series started
			shouldIgnoreLoggingSignal = true;
			 boolean shouldStartLogging = JOptionPane
				.showConfirmDialog(
						this,
						"A training series is being sent to the Resilience Manager, start logging it?",
						"Log training series", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
		
		     if(shouldStartLogging ){
		    	 // the counter auto-check if it has started counting, repeatedly
		    	 // calling it without knowing its state is not dangerous. In fact the
		    	 // counter should have been on if this method is invoked
		    	 autoSubscriber.onStartCounter();
		    	 loggingStarted = true;
		    	 //this.autoSubscriber.setEnabled(false);
                 JOptionPane.showMessageDialog(this, "Please wait till logging has finished.",
							"Logging...", JOptionPane.INFORMATION_MESSAGE);
		     }
		
		}
		else if (publisherStatus.equalsIgnoreCase(
				DemoResource.PUBLISHER_STATUS_FINISHED) && loggingStarted){
			  
			  loggingStarted = false;
			  
			  boolean shouldSaveData = JOptionPane
				.showConfirmDialog(
						this,
						"The anaylzer has finished logging. Do you want to save" +
						" the data? (You can analyze without saving it, but saved log files allow you to reuse the " +
						" training data)",
						"Save log file", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
		      if(shouldSaveData){
		    	  
		    	  if(saveDataIntoFile()){
		    		  
		    	  }
		    	  else{
		    		  JOptionPane.showMessageDialog(this, "Saving failed, check if the current user has right" +
		    		  		" to write to disk, or if data source is still available.",
								"Failure to save file", JOptionPane.INFORMATION_MESSAGE);
		    	  }
		      }
		      

		      // reactive user control over the GUI and enable the analyze button
			  //this.autoSubscriber.setEnabled(true);
			  this.analyzeCovButton.setEnabled(true);
			  
			  boolean shouldStartAnalysis = JOptionPane
				.showConfirmDialog(
						this,
						"The anaylzer has captured enough data to start with. Do you want to process " +
						"the data? (You can also press analyze button under the Analyzer Tab to process data)",
						"Training series received", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
		      if(shouldStartAnalysis ){
		    	  // only disable anaylze option after data has really been analzyed
		    	  if(convertTrainingDataToCovariance()){
		    	      this.analyzeCovButton.setEnabled(false);
		    	  }
		      } 

		}
		else return;
	}
	
	// this method allows using captured data series to calculate covariance matrix from 
	private boolean convertTrainingDataToCovariance(){
	    
		//double[][] msgRate = new double[100][100];
		msgRate = autoSubscriber.getLoggedData();
		namespaces = autoSubscriber.getLoggedNamespace();
		
		return jPanel_namespace.processData(msgRate);
	}
	
	// this method allows loading an existing data file and calculate covariance matrix from it
	private void convertFileDataToCovariance(){
		 
		if(loadDataFromFile()){
			
			// check if something have been read from the file, if the user
			// decided not to select any file, this funtion call will not 
			// spread any further and will stop
			if(msgRate != null && namespaces != null){ 
 
		        //System.out.print(namespaces);
		        //System.out.print(msgRate);
				
		        this.jPanel_namespace.processData(msgRate);
			}
		}
		else{
			JOptionPane.showMessageDialog(this, "Log file loading failed, try load again",
					"Logging...", JOptionPane.INFORMATION_MESSAGE);
			
		}
	}
	
	
	// save message rate into files for future training purpose
    private boolean saveDataIntoFile(){
		 
		JFileChooser fc=new JFileChooser();

		Logfilter filter = new Logfilter();

		fc.setFileFilter(filter);

		int returnVal = fc.showSaveDialog(this);
   
		msgRate = null;
		
		namespaces = null;
		 
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			File saveFile = fc.getSelectedFile();
			try{ 
				
                // save data into log files
		    	if(autoSubscriber!=null && autoSubscriber.logData(saveFile)){
		    		  
		    		return true;
		    	}
		    	else{
		    		return false;
		    	}
			      
			}
            catch(Exception e) { e.printStackTrace(); return false;}
		     
		}
		else
		{ 

			return true;
 
		} 
	}
	
	
	// load message rate as training data and pass it as
	// 2D double arrays onto covariance calculation function
    private boolean loadDataFromFile(){
		 
		JFileChooser fc=new JFileChooser();

		Logfilter filter = new Logfilter();

		fc.setFileFilter(filter);

		int returnVal = fc.showOpenDialog(this);
 
		LogFileReader logReader;
		
		msgRate = null;
		
		namespaces = null;
		 
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			file = fc.getSelectedFile();
			try{ 
				logReader = new LogFileReader(new FileReader(file), '\t', 0);
			  
				msgRate = logReader.readAll();
				namespaces = logReader.readNsName();
	        	 
	    		return true;
	        	
			}
            catch(Exception e) { e.printStackTrace(); return false;}
		     
		}
		else
		{ 

			return true;
 
		}
		
		
	}
	
	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setText("Add");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					modify=false;
					d=getDialog_gbroker();
					d.show();

					
				}
			});
		}
		jButton.setEnabled(false);
		return jButton;
	}

	/**
	 * This method initializes jButton_modify	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton_modify() {
		if (jButton_modify == null) {
			jButton_modify = new JButton();
			jButton_modify.setText("Modify");
			jButton_modify.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					modify=true;
					d=getDialog_gbroker();
					d.show();

					
				}
			});
		}
//		TODO enable modify 
		jButton_modify.setEnabled(false);
		return jButton_modify;
	}

	/**
	 * This method initializes jButton_delete	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton_delete() {
		if (jButton_delete == null) {
			jButton_delete = new JButton();
			jButton_delete.setText("Delete");
			jButton_delete.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					 
					int row=gt.getTable().getSelectedRow();
					gt.deletRow(row);
				}
			});
		}
		
		jButton_delete.setEnabled(false);
		return jButton_delete;
	}

	/**
	 * This method initializes jPanel_gbroker	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel_gbroker() {
		if (jPanel_gbroker == null) {
			jPanel_gbroker = new JPanel();
			jPanel_gbroker.setLayout(new BorderLayout());
			jPanel_gbroker.add(getJScrollPane(), BorderLayout.CENTER);
			jPanel_gbroker.add(getJPanel(), BorderLayout.SOUTH);
		}
		return jPanel_gbroker;
	}

	/**
	 * This method initializes jPanel_gbroker	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelAnalyzer() {
		
		
		if (jPanelAnalyzer == null) {    
			jPanelAnalyzer = new JPanel();
			jPanelAnalyzer.setLayout(new BorderLayout());
			jPanelAnalyzer.add(this.autoSubscriber = new AutoSubscriber(1, this), BorderLayout.CENTER);
			//jPanelAnalyzer.add(jScrollPaneAnalyzer = new JScrollPane(), BorderLayout.CENTER);
			jPanelAnalyzer.add(getJPanelAnalyzerControl(), BorderLayout.SOUTH);
		}
		return jPanelAnalyzer;
	}
	
	
    private boolean loadScenario(){
		
		DefaultMutableTreeNode top;

		JFileChooser fc=new JFileChooser();

		XMLfilter filter = new XMLfilter();

		fc.setFileFilter(filter);

		int returnVal = fc.showOpenDialog(this);

		if (returnVal == JFileChooser.APPROVE_OPTION) {
			file = fc.getSelectedFile();
		
		    scenarioParser= new ScenarioFileParser(file);

		    startAnalyzerButton.setEnabled(true);
		    analyzeCovButton.setEnabled(false);  
		    
		    return true;
		}
		else
		{
			return false;
		}
		
	}
	
	/**
	 * This method initializes jButton_load	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton_load() {
		if (jButton_load == null) {
			jButton_load = new JButton();
			jButton_load.setText("Load");
			jButton_load.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					loadAction();
				}
			});
		}
		return jButton_load;
	}
	
	
	/**
	 * The load button action
	 * **/
	
	private void loadAction(){
		
		
		JFileChooser fc=new JFileChooser();

		XMLfilter filter = new XMLfilter();

		fc.setFileFilter(filter);

		int returnVal = fc.showOpenDialog(this);

		if (returnVal == JFileChooser.APPROVE_OPTION) {
			// get the scenario file
			File file = fc.getSelectedFile();
			scParser sp= new scParser(file);
			
			Vector<Gbroker> gblist= sp.getGB();
			
			for(int i=0; i<gblist.size(); i++)
			{
//				gt.createRow(gblist.get(i).getCAP(),0.05);
				gt.createRow(gblist.get(i),0.05);
				
				
			}
			iniFrame.brokerConfigured = true;
		}
	}

	/**
	 * This method initializes namespace tree panel	
	 * 	
	 * @return treePanel	
	 */
	private treePanel getJPane_namespace() {
		if (jPanel_namespace == null) {
			jPanel_namespace = new treePanel(this, cd);
		}
		return jPanel_namespace;
	}

	/**
	 * This method initializes dialog_gbroker	
	 * 	
	 * @return java.awt.Dialog	
	 */
	private Dialog getDialog_gbroker() {
		if (dialog_gbroker == null) {
			dialog_gbroker = new Dialog(this);
			dialog_gbroker.setTitle("Gbroker Information");
			dialog_gbroker.setSize(new Dimension(221, 112));
			dialog_gbroker.add(getJPanel_button(), BorderLayout.SOUTH);
			dialog_gbroker.add(getJPanel_label(), BorderLayout.CENTER);
			
			Dimension scr = Toolkit.getDefaultToolkit().getScreenSize(); 
			Dimension frm = dialog_gbroker.getSize(); 
			dialog_gbroker.setLocation( (scr.width - frm.width) / 2, 
					(scr.height - frm.height) / 2 - 18); 
		}
		return dialog_gbroker;
	}

	/**
	 * This method initializes dialog_add	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getDialog_add() {
		if (dialog_add == null) {
			dialog_add = new JButton();
			dialog_add.setText("OK");
			dialog_add.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					
					addAction();
					
				}
			});
		}
		return dialog_add;
	}
	
	
	private void addAction(){
		
		pc=Double.parseDouble(jTextField_cap.getText());
		pth= Double.parseDouble(jTextField_th.getText());
		
		if(!modify)
		{
		gt.createRow(pc, pth);
		}
		else{
			int row=gt.getTable().getSelectedRow();
			gt.modifyRow(row, pc, pth);
		}
		d.dispose();
		
	}

	/**
	 * This method initializes jPanel_button	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel_button() {
		if (jPanel_button == null) {
			GridLayout gridLayout1 = new GridLayout();
			gridLayout1.setRows(1);
			jPanel_button = new JPanel();
			jPanel_button.setLayout(gridLayout1);
			jPanel_button.add(getDialog_add(), null);
			jPanel_button.add(getDialog_no(), null);
		}
		return jPanel_button;
	}

	/**
	 * This method initializes dialog_no	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getDialog_no() {
		if (dialog_no == null) {
			dialog_no = new JButton();
			dialog_no.setText("Cancel");
			dialog_no.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					d.dispose();
				}
			});
		}
		return dialog_no;
	}

	/**
	 * This method initializes jPanel_label	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel_label() {
		if (jPanel_label == null) {
			jLabel_threshold = new JLabel();
			jLabel_threshold.setText("Threshold");
			jLabel_cap = new JLabel();
			jLabel_cap.setText("Capability");
			GridLayout gridLayout2 = new GridLayout();
			gridLayout2.setRows(2);
			gridLayout2.setColumns(2);
			jPanel_label = new JPanel();
			jPanel_label.setLayout(gridLayout2);
			jPanel_label.add(jLabel_cap, null);
			jPanel_label.add(getJTextField_cap(), null);
			jPanel_label.add(jLabel_threshold, null);
			jPanel_label.add(getJTextField_th(), null);
		}
		return jPanel_label;
	}

	/**
	 * This method initializes jTextField_cap	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField_cap() {
		if (jTextField_cap == null) {
			jTextField_cap = new JTextField();
		}
		return jTextField_cap;
	}

	/**
	 * This method initializes jTextField_th	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField_th() {
		if (jTextField_th == null) {
			jTextField_th = new JTextField();
		}
		return jTextField_th;
	}

}  //  @jve:decl-index=0:visual-constraint="155,73"

class Logfilter extends javax.swing.filechooser.FileFilter{
	public boolean accept(File f) {
		return f.isDirectory() || f.getName().toLowerCase().endsWith(".log");
	}

	public String getDescription() {
		return ".log files";
	}
}

